define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $('.btn-editone').data('area',['90%','90%']);
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'person/index' + location.search,
                    add_url: 'person/add',
                    edit_url: 'person/edit',
                    del_url: 'person/del',
                    multi_url: 'person/multi',
                    import_url: 'person/import',
                    table: 'person',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle:false,
                showColumns:false,
                searchFormVisible:true,
                search:false,
                showExport:false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'name', title: __('部门'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex')},
                        {field: 'age', title: __('Age')},
                        {field: 'nation', title: __('Nation'), operate: 'LIKE'},
                        {field: 'blood', title: __('Blood'), operate: 'LIKE'},
                        {field: 'political', title: __('Political'), operate: 'LIKE'},
                        {field: 'health_situation', title: __('Health_situation'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'idcard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'birthday', title: __('Birthday'), operate: 'LIKE'},
                        {field: 'marriage_situation', title: __('Marriage_situation'), operate: 'LIKE'},
                        {field: 'wedding_date', title: __('Wedding_date'), operate: 'LIKE'},
                        {field: 'childrener', title: __('Childrener'), operate: 'LIKE'},
                        {field: 'qualification', title: __('Qualification'), operate: 'LIKE'},
                        {field: 'english_level', title: __('English_level'), operate: 'LIKE'},
                        {field: 'graduate', title: __('Graduate'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'graduate_date', title: __('Graduate_date'), operate: 'LIKE'},
                        {field: 'major', title: __('Major'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'qualification_level', title: __('Qualification_level'), operate: 'LIKE'},
                        {field: 'is_crime', title: __('Is_crime')},
                        {field: 'employ_state', title: __('Employ_state')},
                        {field: 'is_pregnancy', title: __('Is_pregnancy'), operate: 'LIKE'},
                        {field: 'residence', title: __('Residence'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'phone_number', title: __('Phone_number'), operate: 'LIKE'},
                        {field: 'myphone_number', title: __('Myphone_number'), operate: 'LIKE'},
                        {field: 'urgent_contacter_one', title: __('Urgent_contacter_one'), operate: 'LIKE'},
                        {field: 'urgent_address_one', title: __('Urgent_address_one'), operate: 'LIKE'},
                        {field: 'urgent_phone_one', title: __('Urgent_phone_one'), operate: 'LIKE'},
                        {field: 'urgent_contacter_two', title: __('Urgent_contacter_two'), operate: 'LIKE'},
                        {field: 'urgent_address_two', title: __('Urgent_address_two'), operate: 'LIKE'},
                        {field: 'urgent_phone_two', title: __('Urgent_phone_two'), operate: 'LIKE'},
                        {field: 'contacter_phone', title: __('Contacter_phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: '', title: __('教育培训'), operate: false,
                            formatter: function (value,row,index) {
                                return '<a href="person/education/ids/'+row.id+'" data-area=["75%","75%"] class="btn btn-success btn-xs btn-dialog" title="'+row.name+'-教育培训">教育培训</a>';
                            }
                        },
                        {field: '', title: __('工作经历'), operate: false,
                            formatter: function (value,row,index) {
                                return '<a href="person/experience/ids/'+row.id+'" data-area=["75%","75%"] class="btn btn-success btn-xs btn-dialog" title="'+row.name+'-工作经历">工作经历</a>';
                            }
                        },
                        {field: '', title: __('家庭成员'), operate: false,
                            formatter: function (value,row,index) {
                                return '<a href="person/family/ids/'+row.id+'" data-area=["75%","75%"] class="btn btn-success btn-xs btn-dialog" title="'+row.name+'-家庭成员">家庭成员</a>';
                            }
                        },
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'employment_unit', title: __('Employment_unit'), operate: 'LIKE'},
                        {field: 'apply_gangwei', title: __('Apply_gangwei'), operate: 'LIKE'},
                        {field: 'states', title: __('States')},
                        // {field: 'create_id', title: __('Create_id')},
                        {field: 'create_time', title: __('创建日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            width:150,
                            formatter: Table.api.formatter.buttons,
                            buttons: [
                                {
                                    name: 'dispatch',
                                    text: '',
                                    icon: 'fa fa-pencil',
                                    extend: "data-area='[\"90%\", \"90%\"]'",
                                    title: '编辑',
                                    url: $.fn.bootstrapTable.defaults.extend.edit_url,
                                    classname: 'btn btn-success btn-xs btn-dialog',
                                },{
                                    name: 'dispatch',
                                    text: '',
                                    icon: 'fa fa-trash',
                                    title: '删除',
                                    classname: 'btn btn-danger btn-xs btn-ajax',
                                    url: $.fn.bootstrapTable.defaults.extend.del_url,
                                    confirm: '确定要删除吗？',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
